//
//  OnlinePeopleDataSource.m
//  tcpoctest
//
//  Created by gump on 5/15/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "OnlinePeopleDataSource.h"

@implementation OnlinePeopleDataSource

-(id)init
{
    self = [super init];
    
    if (self)
    {
        showArr = [[NSMutableArray alloc] init];
        pthread_mutex_init(&mutexonline, 0);
    }
    
    return self;
}

-(int)GetOnlinePeopleOrder
{
    int io = getOnLineOrder();
    
    if (io == OLOT_NULL) {
        if ([DataControl shareControl].personDS.uinfo != nil) {
            if ([DataControl shareControl].personDS.uinfo.sex == 1) {
                setOnLineOrder(OLOT_MALE);
                io = OLOT_MALE;
            }
            else
            {
                setOnLineOrder(OLOT_FAMALE);
                io = OLOT_FAMALE;
            }
        }
    }
    
    return io;
}

-(void)AddShowArr:(NSString *)strmail
{
    pthread_mutex_lock(&mutexonline);
    
    if (strmail != nil &&
        ![strmail isEqualToString:@""] &&
        ![showArr containsObject:strmail]) {
        [showArr addObject:strmail];
    }
    
    pthread_mutex_unlock(&mutexonline);
}

-(void)RemoveAll
{
    pthread_mutex_lock(&mutexonline);
    
    [showArr removeAllObjects];
    
    pthread_mutex_unlock(&mutexonline);
}

-(int)GetShowArrCount
{
    int icount = 0;
    
    pthread_mutex_lock(&mutexonline);
    
    icount = [showArr count];
    
    pthread_mutex_unlock(&mutexonline);
    
    return icount;
}

-(NSString *)GetObjectByIndex:(int)iindex
{
    NSString *str = @"";
    
    pthread_mutex_lock(&mutexonline);
    
    if (iindex >= 0  && iindex < showArr.count) {
        str = [showArr objectAtIndex:iindex];
    }
    
    pthread_mutex_unlock(&mutexonline);
    
    return str;

}

-(void)RemoveObjectByIndex:(int)iindex
{
    pthread_mutex_lock(&mutexonline);
    
    if (iindex >= 0  && iindex < showArr.count) {
        [showArr removeObjectAtIndex:iindex];
    }
    
    pthread_mutex_unlock(&mutexonline);
}

@end
